package org.cmg.study.spring.controller;

import org.cmg.study.spring.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;

/**
 * @author CMG
 * @version 1.0
 * @cLassName UserController
 * @description
 * @date 2021/9/3 15:18
 **/
@Controller
@RequestMapping("/param")
public class UserController {
    @RequestMapping("/login")
    public String getLogin(User user, Model model){
        if("xg".equals(user.getName()) &&
         "12345".equals(user.getPasswd())){
            model.addAttribute("message", "登陆成功");
            return "main";//登陆成功 跳转main.jsp
        }else{
            model.addAttribute("message", "用户名或密码错误");
            return "register";
        }
    }

    @RequestMapping("/login1")
    public String getLogin1(String name, String passwd, Model model){
        if("xg".equals(name) &&
                "12345".equals(passwd)){
            model.addAttribute("message", "登陆成功");
            return "main";//登陆成功 跳转main.jsp
        }else{
            model.addAttribute("message", "用户名或密码错误");
            return "register";
        }
    }

    @RequestMapping("/login2")
    public String getLogin2(HttpServletRequest request, Model model){
        String name = request.getParameter("name");
        String passwd = request.getParameter("passwd");
        if("xg".equals(name) &&
                "12345".equals(passwd)){
            model.addAttribute("message", "登陆成功");
            return "main";//登陆成功 跳转main.jsp
        }else{
            model.addAttribute("message", "用户名或密码错误");
            return "register";
        }
    }

    @RequestMapping("/login3")
    public String getLogin3(@PathVariable String name, @PathVariable String passwd, Model model){
        if("xg".equals(name) &&
                "12345".equals(passwd)){
            model.addAttribute("message", "登陆成功");
            return "main";//登陆成功 跳转main.jsp
        }else{
            model.addAttribute("message", "用户名或密码错误");
            return "register";
        }
    }

    @RequestMapping("/login4")
    public String getLogin4(@RequestParam String name, @RequestParam String passwd, Model model){
        if("xg".equals(name) &&
                "12345".equals(passwd)){
            model.addAttribute("message", "登陆成功");
            return "main";//登陆成功 跳转main.jsp
        }else{
            model.addAttribute("message", "用户名或密码错误");
            return "register";
        }
    }
}

